<template>
  <div>
    <el-dialog title="选择数据" :visible.sync="dialogVisible" width="40%">
      <div style="display: flex; align-items: center">
        <div>名称：</div>
        <el-input
          style="width: 300px"
          v-model="name"
          @input="upIcon(name)"
        ></el-input>
      </div>
      <el-table
        :loading="listLoading"
        :data="list"
        style="width: 100%; margin-top: 30px"
        border
        height="550"
      >
        <el-table-column
          align="center"
          type="index"
          label="序号"
        ></el-table-column>
        <el-table-column align="center" prop="id" label="id"></el-table-column>
        <el-table-column
          align="center"
          prop="name"
          label="名称"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="pageInfo"
          label="数据字段"
        ></el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              icon="el-icon-check"
              size="mini"
              @click="dataChange(scope.row)"
              >选择</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<script>
import { getProductListKyk } from "@/api/product";
export default {
  name: "selectData",
  data() {
    return {
      dialogVisible: false,
      name: "",
      tableData: [],
      list: [],
      listLoading: false
    };
  },
  created() {},
  methods: {
    dataChange(v) {
      console.log(v);
      this.$emit("selectData", v);
      this.dialogVisible = false;
    },
    getDataList() {
      this.listLoading = true;
      getProductListKyk()
        .then(res => {
          this.tableData = res.data;
          this.list = this.tableData;
          this.listLoading = false;
        })
        .finally(() => {
          this.listLoading = false;
        });
    },
    upIcon(n) {
      const arrs = [];
      this.tableData.forEach(item => {
        if (item.name.indexOf(n) !== -1) {
          arrs.push(item);
          this.list = arrs;
        }
      });
    },
    handleClick() {
      this.getDataList();
      this.dialogVisible = true;
    },
    handleClose() {
      this.dialogVisible = false;
    }
  }
};
</script>

<style scoped lang="scss"></style>
